/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package moviefansystem;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Frank Eggink
 */
public class RealDatabase_old implements IDatabase {

    private static Connection localConnection;

    /**
     * This methods makes the connection to the local database that is running
     * at the Moviefan Shop
     *
     * @throws ClassNotFoundException
     * @throws SQLException
     */
    public void connectToLocalDatabase() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");

        localConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/lokale_database", "root", "");
    }

    @Override
    public int voegNieuweKlantToe(Klant k) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Klant zoekKlant(int klantnummer) {
        try {
            //throw new UnsupportedOperationException("Not supported yet.");
            PreparedStatement statement = (PreparedStatement) localConnection.prepareStatement("SELECT films.Titel, films.Beschrijving, "
                    + "categorie.Naam, taal.Naam  FROM films, categorie, taal "
                    + "WHERE films.Categorie=categorie.Nummer AND films.Taal = taal.Nummer ");



            ResultSet result = statement.executeQuery();

            //TODO:
            //change the sql statement
            //add klant + add data to klant
            //return Klant;

        } catch (SQLException ex) {
            Logger.getLogger(RealDatabase.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;    //change to return Klant
    }

    @Override
    public boolean maakNieuweReservering(int klantnummer, int filmId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean maakNieuweVerhuurd(int klantnummer, int filmId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean verwijderReservering(int klantnummer, int filmId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList<Film> getPersonlijkeItemsGehuurd(Klant klant) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList<Film> getPersonlijkeItemsGereseveerd(Klant klant) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList<Film> getPersonlijkeItemsInBezit(Klant klant) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int voegNieuweFilmToe(Film film) {
        throw new UnsupportedOperationException("Not supported yet.");
    }


    

    @Override
    public boolean leenItemUit(int klantnummer, int filmId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean neemItemIN(int klantnummer, int filmId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean toonFinancieelOverzicht() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    //some helper methods
    //TODO: change the methods
    /**
     * This method writes the metadata from the ResultSet to the screen
     *
     * @param resultSet
     * @throws SQLException
     */
    private void writeMetaData(ResultSet resultSet) throws SQLException {
        // Now get some metadata from the database
        // Result set get the result of the SQL query

        System.out.println("The columns in the table are: ");

        System.out.println("Table: " + resultSet.getMetaData().getTableName(1));
        for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
            System.out.println("Column " + i + " " + resultSet.getMetaData().getColumnName(i));
        }
    }

    /**
     * This method writes newlines to the screen
     *
     * @param numberOfNewLines is the number of newlines
     */
    private void printNewLines(int numberOfNewLines) {
        int i;
        for (i = 0; i < numberOfNewLines; i++) {
            System.out.println();
        }
    }

    /**
     * This method writes the information in the ResultSet to the screen
     *
     * @param result is the resultset that needs to be printed to the screen
     * @throws SQLException
     */
    private void writeResultSet(ResultSet result) throws SQLException {
        while (result.next()) {
            String filmTitel = result.getString("films.Titel");
            String filmBeschrijving = result.getString("films.beschrijving");
            String categorie = result.getString("categorie.Naam");
            String taal = result.getString("taal.Naam");

            //System.out.println(result.getString(1) + " / " + result.getString(2) + " / " + result.getString(3) + " / " + result.getString(4));
            System.out.println(filmTitel);
            System.out.println(filmBeschrijving);
            System.out.println(categorie);
            System.out.println(taal);
        }
    }

    @Override
    public ArrayList<Film> getAlleFilms() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Film zoekFilm(int artikelNummer) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList<Film> zoekFilm(String omschrijving) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
